﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 会员卡管理系统
{
    public partial class VipStayfrm : Form
    {
        public VipStayfrm()
        {
            InitializeComponent();
        }
        Vipclass.tb_viphouseinfo vipinfo = new Vipclass.tb_viphouseinfo();
        Vipclass.tbVipHouseMenthod vipmenthod = new Vipclass.tbVipHouseMenthod();

        private void VipStayfrm_Load(object sender, EventArgs e)
        {
            vipmenthod.tbVipfoFill(lvVip, imageList1);
            vipmenthod.tbNorusefoFill(cbxhouseid);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                vipmenthod.tbVipfoFind(lvVip, imageList1, textBox1.Text.Trim(), 0);
            }
            else
            {
                if (radioButton2.Checked == true)
                {
                    vipmenthod.tbVipfoFind(lvVip, imageList1, textBox1.Text.Trim(), 1);
                }
                else
                {
                    vipmenthod.tbVipfoFind(lvVip, imageList1, textBox1.Text.Trim(), 2);
                }
            }
        }

        private void lvVip_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvVip.SelectedItems.Count > 0)
            {
                string str = lvVip.SelectedItems[0].Text;
                vipinfo=vipmenthod.tbViptoshow(str);
                labname.Text = vipinfo.Strvipname;
                labid.Text = vipinfo.Strvipid;
                labidcard.Text = vipinfo.Strvipidcard;
            }
        }

        private void btnNo_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            vipinfo.Bolhousestay = 1;
            vipinfo.Strhouseid = cbxhouseid.Text.Trim();
            int givetime = vipmenthod.tbVipTime(labname.Text);
            if(givetime>=10)
            {
                if(MessageBox.Show("你入住次数已满10次，是否免费入住一次！","免费入住提醒",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.Yes)
                {
                    
                    if (vipmenthod.tbhousefoVipuse(vipinfo) == 1&& vipmenthod.tbVipTableUse(labname.Text, givetime - 10)==1)
                    {
                        MessageBox.Show("入住成功！", "提示");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("入住失败！", "错误");
                        this.Close();
                    }
                }
                else
                {
                    if (vipmenthod.tbhousefoVipuse(vipinfo) == 1 && vipmenthod.tbVipTableUse(labname.Text, givetime +1) == 1)
                    {
                        MessageBox.Show("入住成功！", "提示");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("入住失败！", "错误");
                        this.Close();
                    }
                }
            }
            else
            {
                if (vipmenthod.tbhousefoVipuse(vipinfo) == 1 && vipmenthod.tbVipTableUse(labname.Text, givetime + 1) == 1)
                {
                    MessageBox.Show("入住成功！", "提示");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("入住失败！", "错误");
                    this.Close();
                }
            }
        }
    }
}
